package com.tianhua.javs.client.bean.context;

import com.tianhua.javs.client.model.FieldModel;
import com.tianhua.javs.client.model.MethodModel;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:
 * 类级别和javs单文件级别的翻译返回
 * date: 2022/2/16
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Data
public class TranslateResultContext {
    private String className;

    /**
     * 要导入的包
     */
    private List<String> packageList = new ArrayList<>();

    /**
     * javs文件中定义的全局变量
     */
    private Map<String, FieldModel> fieldModelMap = new HashMap<>();

    /**
     * 转译后的方法内容
     */
    private List<MethodModel> methodModelList = new ArrayList<>();


    public void addPackages(List<String> packageList){
        if(CollectionUtils.isEmpty(packageList)){
            return;
        }
        for (String packageName : packageList){
            if(this.packageList.contains(packageName)){
                continue;
            }
            this.packageList.add(packageName);
        }

    }

    public void addMethodModel(MethodModel methodModel){
        this.methodModelList.add(methodModel);
    }

    public void addFieldList(List<FieldModel> fieldModelList){
        for (FieldModel fieldModel : fieldModelList){

            if(fieldModelMap.containsKey(fieldModel.getFieldName())){
                continue;
            }
            this.addPackages(fieldModel.getPackageList());
            fieldModelMap.put(fieldModel.getFieldName(), fieldModel);
        }
    }

}

